<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@taglib uri="http://www.hx.com/tags" prefix="hx" %>
<%   String path = request.getContextPath();   
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
	String bpath = request.getScheme()+"://"+request.getServerName();
	String openId = (String)request.getSession().getAttribute("openId");
	if(openId==null || openId.equals("")){
	 	openId = (String)request.getParameter("openId");
	 	request.getSession().setAttribute("openId", request.getParameter("openId"));	
	}
	 
%>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,,user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="http://v3.bootcss.com/favicon.ico">
    <hx:ajax jquery="true"/>
    <title>微留言</title>
    <link href="/bootstrapDemo/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="/bootstrapDemo/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
    <script src="/bootstrapDemo/js/jquery.js"></script>
	 <script src="/bootstrapDemo/bootstrap/js/bootstrap.min.js"></script>
	 
    <script type="text/javascript">
    	//显示和关闭回复框
    	function showMessageDiv(id){
    		if(document.getElementById(id).style.display){
    			document.getElementById(id).style.display="";
    		}else{
    			document.getElementById(id).style.display="none";
    		}
    	}
    	//隐藏微信下面的工具条。
    	/* function onBridgeReady(){
    		   WeixinJSBridge.call('hideToolbar');
    		}
    		if (typeof WeixinJSBridge == "undefined"){
    		    if( document.addEventListener ){
    		        document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
    		    }else if (document.attachEvent){
    		        document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
    		        document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
    		    }
    		}else{
    		    onBridgeReady();
    		} */
    	//ajax保存
    	function tosubmitAjax(frmid){
    		var content = $("#"+frmid+" textarea").val();
    		if(content!=null && content!="" && content!="undefined"){
    			 var murl = "<%=basePath%>/messageBoard/saveMessage.action";
        		var parmers = $("#"+frmid).serialize();
        		$.post(murl,parmers,function(boo){
        			if(boo){
        				 document.getElementById("successDiv").style.display="";
        				 location.href = "<%=basePath%>/messageBoard/getWmessageList.action";
        			}else{
        				document.getElementById("failureDiv").style.display="";
        			}
        			
        		});
    		}else{
    			alert("请填写留言内容！");
    		}
    		
    	}
    	
    </script>
  </head>
  
<body>
<img src="/images/message_boards.jpg" alt="..." width="100%"  style="height: 70px">
<img src="/images/edit_message.jpg" alt="..." width="100%"  style="height: 70px" onclick="showMessageDiv('mainMsg')">
<div class="jumbotron" style="padding: 0px;font-size: 14px;margin: 0px;"> 
		<div class="alert alert-success alert-dismissable" id="successDiv" style="margin: 0px;display: none">
		   <button type="button" class="close" data-dismiss="alert" 
		      aria-hidden="true">
		      &times;
		   </button>
		  操作成功！您已经很好的完成了提交。
		</div>
		<div class="alert alert-warning alert-dismissable" id="failureDiv" style="margin: 0px;display: none">
		   <button type="button" class="close" data-dismiss="alert" 
		      aria-hidden="true">
		      &times;
		   </button>
		   操作失败！请重新尝试。
		</div>
		<div id = "mainMsg" style="display: none" >
			<div style="color: green;background-image: url('/images/bak_message.jpg');">
				<label style="margin-left: 21px;color: green;">●</label><label style="margin-left: 12px;">填写留言</label>
			</div>
			<div style="background-image: url('/images/bak_message.jpg');">
				<form name="messageAddFrm" id="messageAddFrm" action="" method="post" >
				<div style="margin-left: 40px;margin-right: 20px;">
					<input type="hidden" name="messageBoard.fkMId" value="0">
					<input type="hidden" name="messageBoard.MUsername" value="${tuser.WNickname }">
					<input type="hidden" name="messageBoard.MOpenid" value="${tuser.WOpenid}">
					<textarea rows="2" cols="1" class="form-control" id="inputRemark" placeholder="请输入留言" style="margin-bottom: 10px;" name="messageBoard.MContent"></textarea> 
					<button type="button" class="btn btn-success" style="width: 100%" onclick="tosubmitAjax('messageAddFrm');">提交</button>
				</div>
				</form>
			</div>
		</div>
	
		<s:iterator value="messageMap" id="column" status="status">
		<div >
			<div style="color: green;background-image: url('/images/bak_message.jpg');">
				<label style="margin-left: 21px;color: green;">●</label><label style="margin-left: 12px;"><s:property value="#column.key.MUsername"/></label>
			</div>
			<div style="background-image: url('/images/bak_message.jpg');line-height: 20px;">
				<label style="margin-left: 40px;"><s:property value="#column.key.MContent"/><br/><small style="color: gray;"><s:date name="#column.key.MDate" format="yyyy-MM-dd hh:mm:ss" /> </small><a style="color: green;font-size: 12px;" href="javascript:showMessageDiv('${key.id}')">回复</a></label>
				<form name="messageHFAddFrm" id="${key.id}frm" action="/messageBoard/saveMessage.action" method="post" >
				<div style="margin-left: 40px;margin-right: 20px;display: none;" id="${key.id}">
					<input type="hidden" name="messageBoard.fkMId" value="${key.id }">
					<input type="hidden" name="messageBoard.MUsername" value="${tuser.WNickname }">
					<input type="hidden" name="messageBoard.MOpenid" value="${tuser.WOpenid}">
					<textarea rows="2" cols="1" name="messageBoard.MContent" class="form-control" id="inputRemarkMsg" placeholder="请输入留言" style="margin-bottom: 10px;"></textarea> 
					<button type="button" class="btn btn-success" style="width: 100%" onclick="tosubmitAjax('${key.id}frm');">提交</button>
				</div>
				</form>
				<s:if test="#column.value.size>0">
				<s:iterator value="#column.value" status="s" id="mes">
				<label style="margin-left: 40px;">
					<blockquote class="pull-left" style="padding: 0px;margin: 0px;">
					  <small style="line-height:15px;"><s:date name="MDate" format="yyyy-MM-dd hh:mm:ss" />  <font color="black"><s:property value="MUsername"/></font>回复<font color="black"><s:property value="#column.key.MUsername"/></font>:</small>
					<s:property value="MContent"/>
					</blockquote>
				</label>
				</s:iterator>
				</s:if>
				
				
			</div>
		</div>
		</s:iterator>
		
		<div >
			<div style="background-image: url('/images/bak_message.jpg');background-repeat: repeat-y;text-align: center;">
				<a href="/messageBoard/getMoredWmessageList.action"><small style="color: gray;">点击加载更多...</small></a>
			</div>
		</div>
	 <div id="footer" style="height: 40px; text-align: center;margin:10px 0px 30px;">
	 	<p>版权所有@功夫梦·中国 2014-2016</p>
	 </div>
		 
    <jsp:include page="/wpages/bottom.jsp"></jsp:include>
</div>
</body>
</html>
